package com.vietnam.power.persistence;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Type;
import com.vietnam.power.dao.IAuditUpdateTable;

/**
 * The persistent class for the product database table.
 * 
 */
@Entity
@Table(name="product")
public class Product implements Serializable, IAuditUpdateTable {
	private static final long serialVersionUID = 1L;
	private Long productId;
	private Date createdDate;
	private boolean deleted;
	private String description;
	private String productName;
	private boolean sold;
	private double unitPrice;
	private Date updatedDate;
	private List<ProductComment> productComments;
	private Location location;
	private UserInfo createdBy;
	private UserInfo updatedBy;
	private Category category;
	private List<ProductChat> productChats;
	private List<ProductImage> productImages;
	private List<ProductLike> productLikes;
	private List<ProductOffer> productOffers;
	private List<ProductReport> productReports;

	public Product() {
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "PRODUCT_ID")
	public Long getProductId() {
		return this.productId;
	}

	public void setProductId(Long productId) {
		this.productId = productId;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_DATE")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	@Type(type = "true_false")
	public boolean getDeleted() {
		return this.deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "PRODUCT_NAME")
	public String getProductName() {
		return this.productName;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}
	
	@Type(type = "true_false")
	public boolean getSold() {
		return this.sold;
	}

	public void setSold(boolean sold) {
		this.sold = sold;
	}

	@Column(name = "UNIT_PRICE")
	public double getUnitPrice() {
		return this.unitPrice;
	}

	public void setUnitPrice(double unitPrice) {
		this.unitPrice = unitPrice;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "UPDATED_DATE")
	public Date getUpdatedDate() {
		return this.updatedDate;
	}

	public void setUpdatedDate(Date updatedDate) {
		this.updatedDate = updatedDate;
	}

	// bi-directional many-to-one association to Comment
	@OneToMany(mappedBy = "product")
	public List<ProductComment> getProductComments() {
		return this.productComments;
	}

	public void setProductComments(List<ProductComment> comments) {
		this.productComments = comments;
	}

	public ProductComment addProductComment(ProductComment comment) {
		getProductComments().add(comment);
		comment.setProduct(this);

		return comment;
	}

	public ProductComment removeProductComment(ProductComment comment) {
		getProductComments().remove(comment);
		comment.setProduct(null);

		return comment;
	}

	// bi-directional many-to-one association to Location
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "LOCATION_ID")
	public Location getLocation() {
		return this.location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}

	// bi-directional many-to-one association to ProductChat
	@OneToMany(mappedBy = "product")
	public List<ProductChat> getProductChats() {
		return this.productChats;
	}

	public void setProductChats(List<ProductChat> productChats) {
		this.productChats = productChats;
	}

	public ProductChat addProductChat(ProductChat productChat) {
		getProductChats().add(productChat);
		productChat.setProduct(this);

		return productChat;
	}

	public ProductChat removeProductChat(ProductChat productChat) {
		getProductChats().remove(productChat);
		productChat.setProduct(null);

		return productChat;
	}

	// bi-directional many-to-one association to ProductImage
	@OneToMany(mappedBy = "product")
	public List<ProductImage> getProductImages() {
		return this.productImages;
	}

	public void setProductImages(List<ProductImage> productImages) {
		this.productImages = productImages;
	}

	public ProductImage addProductImage(ProductImage productImage) {
		getProductImages().add(productImage);
		productImage.setProduct(this);

		return productImage;
	}

	public ProductImage removeProductImage(ProductImage productImage) {
		getProductImages().remove(productImage);
		productImage.setProduct(null);

		return productImage;
	}

	// bi-directional many-to-one association to ProductLike
	@OneToMany(mappedBy = "product")
	public List<ProductLike> getProductLikes() {
		return this.productLikes;
	}

	public void setProductLikes(List<ProductLike> productLikes) {
		this.productLikes = productLikes;
	}

	public ProductLike addProductLike(ProductLike productLike) {
		getProductLikes().add(productLike);
		productLike.setProduct(this);

		return productLike;
	}

	public ProductLike removeProductLike(ProductLike productLike) {
		getProductLikes().remove(productLike);
		productLike.setProduct(null);

		return productLike;
	}

	// bi-directional many-to-one association to ProductOffer
	@OneToMany(mappedBy = "product")
	public List<ProductOffer> getProductOffers() {
		return this.productOffers;
	}

	public void setProductOffers(List<ProductOffer> productOffers) {
		this.productOffers = productOffers;
	}

	public ProductOffer addProductOffer(ProductOffer productOffer) {
		getProductOffers().add(productOffer);
		productOffer.setProduct(this);

		return productOffer;
	}

	public ProductOffer removeProductOffer(ProductOffer productOffer) {
		getProductOffers().remove(productOffer);
		productOffer.setProduct(null);

		return productOffer;
	}

	// bi-directional many-to-one association to ProductReport
	@OneToMany(mappedBy = "product")
	public List<ProductReport> getProductReports() {
		return this.productReports;
	}

	public void setProductReports(List<ProductReport> productReports) {
		this.productReports = productReports;
	}

	public ProductReport addProductReport(ProductReport productReport) {
		getProductReports().add(productReport);
		productReport.setProduct(this);

		return productReport;
	}

	public ProductReport removeProductReport(ProductReport productReport) {
		getProductReports().remove(productReport);
		productReport.setProduct(null);

		return productReport;
	}

	// bi-directional many-to-one association to Category
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CATEGORY_ID")
	public Category getCategory() {
		return this.category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	@Override
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "CREATED_BY")
	public UserInfo getCreatedBy() {
		return this.createdBy;
	}

	@Override
	public void setCreatedBy(UserInfo createdBy) {
		this.createdBy = createdBy;
	}

	@Override
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "UPDATED_BY")
	public UserInfo getUpdatedBy() {
		return this.updatedBy;
	}

	@Override
	public void setUpdatedBy(UserInfo updatedBy) {
		this.updatedBy = updatedBy;
	}
}